package com.jianglin.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jianglin.mapper.PropertyInfoMapper;
import com.jianglin.model.PropertyInfo;
import com.jianglin.service.IPropertyInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Service
public class PropertyInfoServiceImpl  implements IPropertyInfoService {

    @Autowired
    private PropertyInfoMapper propertyInfoDao;

    @Override
    public PageInfo<PropertyInfo> findPropertyInfoAll(int page, int pagesise, PropertyInfo propertyInfo) {
        PageHelper.startPage(page, pagesise);
        List<PropertyInfo> list = propertyInfoDao.queryListAll(propertyInfo);
        return new PageInfo<>(list);
    }
    @Override
    public void deleteInfoByHouIdAndTime(Integer houId, Date endTime) {
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        String dateString = formatter.format(endTime);
        propertyInfoDao.deleteByHouIdAndTime(houId, dateString);
    }

    @Override
    public PageInfo<PropertyInfo> findListByPage(Integer page, Integer pageCount) {
        PageHelper.startPage(page, pageCount);
        List<PropertyInfo> list = propertyInfoDao.queryListAll(new PropertyInfo());
        return new PageInfo<>(list);
    }

    @Override
    public int add(PropertyInfo propertyInfo) {
        return propertyInfoDao.insert(propertyInfo);
    }

    @Override
    public int delete(Long id) {
        return propertyInfoDao.deleteById(id);
    }

    @Override
    public int updateStatus(Long id, Integer status) {
        return propertyInfoDao.updateStatus(id, status);
    }

    @Override
    public PropertyInfo findById(Long id) {
        return propertyInfoDao.selectById(id);
    }
}
